package com.reabam.tryshopping.h5.reabampos;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class MainActivity extends FlutterActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        FlutterAndroidFullScreenUtils.setFullScreen(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        FlutterAndroidFullScreenUtils.release();
        super.onDestroy();
    }

    @Override
    public void configureFlutterEngine(FlutterEngine flutterEngine){
        super.configureFlutterEngine(flutterEngine);

        //给当前页面注册自定义临时android插件
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        XFlutterProjectAndroidPlugin.registerWith(flutterEngine, this);

    }


    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        XScannerOutputUtils.upKey(keyCode);
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.i("XSDK","---onKeyDown,keyCode="+keyCode);
        String outputStr=XScannerOutputUtils.downKey(keyCode);
        if(outputStr!=null){
            Log.i("XSDK","---onKeyDown,outputStr="+outputStr);
            //原生通知flutter
            XFlutterProjectAndroidPlugin.nativeSendMessageToFlutter("android_keyboard_listener",outputStr);
        }

        return super.onKeyDown(keyCode, event);

    }


}
